﻿using System;
using NDesk.Options;

namespace JoePack
{
    class Program
    {

        public static void Main(string[] args)
        {
            Console.WriteLine("JoePack started!");

            string catalogPath;
            string solutionPath;
            bool showHelp;
            var options = ArgumentParser.Parse(args, out catalogPath, out solutionPath, out showHelp);
           
            if (showHelp)
            {
                ShowHelp(options);
                return; 
            }


            Catalog catalog = Catalog.Parse(catalogPath);
            Console.WriteLine(String.Format("CataLog loaded from:{0}",catalogPath));

            Dependencies dependencies = Dependencies.Load(catalog, solutionPath);
            Console.WriteLine("Dependencies loaded from:{0}",solutionPath);
            Console.WriteLine("{0} Packages will be synced and all their dependencies!",dependencies.Packages.Count);
            Console.WriteLine("Root packages to sync:");
            foreach (var p in dependencies.Packages)
            {
                Console.WriteLine(p.Name);
            }

            Console.WriteLine("Starting Syncing!");
            dependencies.Update();
            Console.WriteLine("Syncing completed!");
        }

        static void ShowHelp(OptionSet p)
        {
            Console.WriteLine("Usage: JoePack -c -s");
            Console.WriteLine("Create a _Reference folder and sync packages into this folder.");
            Console.WriteLine();
            Console.WriteLine("Options:");
            p.WriteOptionDescriptions(Console.Out);
        } 

    }
}

